package com.pinyougou.manager.controller;

import com.github.pagehelper.PageInfo;
import entity.ResultInfo;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.pojo.TbBrand;
import com.pinyougou.sellergoods.service.BrandService;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/brand")
public class BrandController {
	
	@Reference
	private BrandService brandService;

	/**
	 * 分页查询所有品牌
	 * @param currentPage
	 * @param size
	 * @return
	 */
	@RequestMapping("/findAll")
	public PageInfo findAll(@RequestParam("pageNum") Integer currentPage, @RequestParam("pageSize") Integer size){

		return brandService.findAll(currentPage,size);
    }

	/**
	 *
	 * @param id
	 * @return
	 */
	@RequestMapping("/findOne")
	public TbBrand findOne(Long id){
		return brandService.findOne(id);
	}
	/**
	 * 添加
	 * @param brand
	 * @return
	 */
	@RequestMapping("/add")
    public ResultInfo add(@RequestBody TbBrand brand){
		try {
			brandService.add(brand);
			return new ResultInfo(true,"添加成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultInfo(false,"添加失败");
		}
	}

	/**
	 * 更新
	 * @param brand
	 * @return
	 */
	@RequestMapping("/update")
	public ResultInfo update(@RequestBody TbBrand brand){

		try {
			brandService.update(brand);
			return new ResultInfo(true,"更新成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultInfo(false,"更新失败");
		}
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@RequestMapping("/delete")
	public ResultInfo delete(Long[] ids){

		try {
			brandService.delete(ids);
			return new ResultInfo(true,"删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultInfo(false,"删除失败");
		}
	}

	@RequestMapping("/search")
	public PageInfo search(@RequestBody TbBrand brand, @RequestParam("pageNum") Integer currentPage, @RequestParam("pageSize") Integer size ){

		return brandService.findAll(brand,currentPage,size);
	}

	@RequestMapping("/selectOptionList")
	public List<Map> selectOptionList(){

		return brandService.selectOptionList();
	}
}
